﻿using System;
using System.Collections.Generic;

using System.Text;

namespace System.Qizx.Xml
{
    /*******************************/
    /// <summary>
    /// Manages the source XML document that will be transformed.
    /// </summary>
    public class GenericSource : BasicSource
    {
        /// <summary>
        /// Represents the type of the source.
        /// </summary>
        public enum TYPE { Uri, Stream, Reader, File }

        private string id;
        private string path;
        private System.IO.StreamReader reader;
        private System.IO.Stream stream;
        private TYPE type;

        /// <summary>
        /// Gets and sets the Id of the GenericSourceSupport instance.
        /// </summary>
        public virtual string Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
                this.path = value;
                this.reader = null;
                this.stream = null;
                this.type = TYPE.Uri;
            }
        }

        /// <summary>
        /// Gets and sets the type of the instance.
        /// </summary>
        public virtual TYPE Type
        {
            get
            {
                return type;
            }
            set
            {
                type = value;
            }
        }

        /// <summary>
        /// Gets and sets the path of the GenericSourceSupport instance.
        /// </summary>
        public virtual string Path
        {
            get
            {
                return this.path;
            }
            set
            {
                this.path = value;
            }
        }

        /// <summary>
        /// Get and sets the stream of the instance.
        /// </summary>
        public virtual System.IO.Stream Stream
        {
            get
            {
                return this.stream;
            }
            set
            {
                this.stream = value;
                this.type = TYPE.Stream;
            }
        }

        /// <summary>
        /// Get and sets the stream of the instance.
        /// </summary>
        public virtual System.IO.StreamReader Reader
        {
            get
            {
                return this.reader;
            }
            set
            {
                this.reader = value;
                this.type = TYPE.Reader;
            }
        }


        /// <summary>
        /// Creates a new instance from an URI.
        /// </summary>
        /// <param name="Uri"></param>
        public GenericSource(string Uri)
        {
            this.id = Uri;
            this.path = Uri;
            this.reader = null;
            this.stream = null;
            this.type = TYPE.Uri;
        }

        /// <summary>
        /// Creates a new instance form the specified StreamReader with the specified Id.
        /// </summary>
        /// <param name="reader">The StreamReader instance with the XML.</param>
        /// <param name="Id">The Id of the instance.</param>
        public GenericSource(System.IO.StreamReader Reader, string Id)
        {
            this.id = Id;
            this.path = "";
            this.reader = Reader;
            this.stream = reader.BaseStream;
            this.type = TYPE.Stream;
        }

        /// <summary>
        /// Creates a new instance from the specified StreamReader.
        /// </summary>
        /// <param name="reader">The StreamReader instance with the XML.</param>
        public GenericSource(System.IO.StreamReader Reader)
        {
            this.id = null;
            this.path = "";
            this.reader = Reader;
            this.stream = reader.BaseStream;
            this.type = TYPE.Stream;
        }

        /// <summary>
        /// Creates a new instance from the specified Stream with the specified Id.
        /// </summary>
        /// <param name="stream">The Stream instance with the XML.</param>
        /// <param name="Id">The Id of the instance.</param>
        public GenericSource(System.IO.Stream Stream, string Id)
        {
            this.id = Id;
            this.path = "";
            this.reader = null;
            this.stream = Stream;
            this.type = TYPE.Stream;
        }

        /// <summary>
        /// Creates a new instance from the specified Stream.
        /// </summary>
        /// <param name="stream">The Stream intance with the XML.</param>
        public GenericSource(System.IO.Stream Stream)
        {
            this.id = null;
            this.path = "";
            this.stream = Stream;
            this.reader = null;
            this.type = TYPE.Stream;
        }

        /// <summary>
        /// Creates a new instance from a FileInfo.
        /// </summary>
        /// <param name="file">The fileInfo instance with the XML.</param>
        public GenericSource(System.IO.FileInfo File)
        {
            this.id = File.FullName;
            this.path = File.FullName;
            this.reader = null;
            this.stream = null;
            this.type = TYPE.File;
        }

        /// <summary>
        /// Basic Constructor for the class.
        /// </summary>
        public GenericSource()
        {
            this.id = null;
            this.path = "";
            this.reader = null;
            this.stream = null;
        }
    }

}
